<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/9 0009
 * Time: 9:55
 */
use think\Db;
//获取
function getMSeo(){
    $data =Db::name('company')->find();
    $md = Db::name('md')->where('is_del=0 and is_show=1')->select();
    if($md){
        $data['md']=$md;
    }
    return $data;
}

//点击加1
function addClick($id,$table){

    $res =Db::name($table)->where('id',$id)->setInc('click');

    return $res;
}

//获取公司信息
function getCompany(){
    $data =Db::name('company')->where('sign="mobile"')->find();
    $data['service_code']=html_entity_decode($data['service_code']);
    return $data;
}

function getMonth($date){
    $where1 = 'is_del=0 and is_show=1 and sign="mobile"';
    if($date){
        $max_year=date('Y',$date);
    }else{
        $sql_1 = 'SELECT FROM_UNIXTIME(ps_time,\'%Y\') nian  FROM `dh_works` where '.$where1.' GROUP BY nian ORDER BY nian DESC  LIMIT 1';
        $max_year =Db::name('works')->query($sql_1);
        $max_year =$max_year[0]['nian'];
    }

    $sql_2 ='SELECT CONCAT(FROM_UNIXTIME(ps_time,\'%Y\'),\'-\',FROM_UNIXTIME(ps_time,\'%m\'),\'-\',CEIL(FROM_UNIXTIME(ps_time,\'%d\')/7)) times FROM `dh_works` where '.$where1.' GROUP BY times';
    $year_month = Db::name('works')->query($sql_2);


    foreach ($year_month  as $k=>$v){
        $nian[]= explode('-',$v['times']);
    }
    foreach ($nian as $k=>$v){
        if(intval($v[0]) == intval($max_year)){
            $yue1[]=$v[1];
            $zhou[]=$v[2];
        }
    }
    $month= array('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月');
    foreach ($month as $key =>$value){
        $month_2[$key][]=$value;
    }
    $week =array('第一周','第二周','第三周','第四周');
    foreach ($week as $key =>$value){
        $week_2[$key][]=$value;
    }

    foreach ($month_2 as $k=>$v){
        foreach ($yue1 as $value){
            if(intval($k+1)  == intval($value)){
                $month_2[$k]['class']='wxz';
            }
        }
    }

    foreach ($week_2 as $k=>$v){
        foreach ($zhou as $value){
            if(intval($k+1)  == intval($value)){
                $week_2[$k]['class']='wxz';
            }
        }
    }

    return $month_2;
}


function getColumnseo($column_id){
    $data =Db::name('seo')->where('column_id',$column_id)->where('sign="mobile"')->find();
    return $data;
}